<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>http://javascript.ruanyifeng.com/stdlib/object.html</title>
</head>
<body>

</body>
</html>

<script type="text/javascript">
    var obj = {};
    console.log(obj);
    Object.prototype.print = function () {
        console.log("print")
    };
    obj.print();
    console.log("--->" + (new Object("abc") instanceof String));
    console.log("--->" + (Object("abc") instanceof String));
    console.log("--->" + (Object(undefined) instanceof Object));

    function isObject(value) {
        return value === Object(value);
    }

    console.log(isObject([])); // true
    console.log(isObject(true)); // false

    var o = {
        p1: 123,
        p2: 456
    };
    console.log(Object.keys(o));
    // ["p1", "p2"]
    console.log(Object.getOwnPropertyNames(o));


    var a = ["Hello", "World"];

    console.log(Object.keys(a));
    // ["0", "1"]

    console.log(Object.getOwnPropertyNames(a));
    // ["0", "1", "length"]

    console.log(Object.keys(o).length);
    console.log(Object.getOwnPropertyNames(o).length);

    console.log(Object.prototype.toString(2)); //
    console.log(Object.prototype.toString.call(2)); // "[object Number]"

    var type = function (o) {
        var s = Object.prototype.toString.call(o);
        return s.match(/\[object (.*?)\]/)[1].toLowerCase();
    };

    console.log(type({})); // "object"
    console.log(type([])); // "array"
    console.log(type(5));// "number"
    console.log(type(null));// "null"
    console.log(type());//"undefined"
    console.log(type(/abcd/)); // "regex"
    console.log(type(new Date())); // "date"

    ['Null', 'Undefined', 'Object', 'Array', 'String', 'Number', 'Boolean', 'Function', 'RegExp', 'NaN', 'Infinite']
        .forEach(function (t) {
            type['is' + t] = function (o) {
                return type(o) === t.toLowerCase();
            };
        });

    console.log(type.isObject({})); // true
    console.log(type.isNumber(NaN)); // true
    console.log(type.isRegExp(/abc/)); // true


    /////////////////////////////////////////////////////
    // http://www.cnblogs.com/TomXu/archive/2011/12/31/2289423.html
    // 立即函数

    (function () {
        console.log("立即执行")
    })();

    (function () {
        console.log("也是立即执行")
    }());

</script>




